﻿using System.Globalization;
using Beaker;
using OpenCube.Nbt.Mapping;

namespace OpenCube.Model.Primitives.Converters
{
	public sealed class IntegerStringConverter
		: NbtSimpleTypeConverter<int, string>
	{
		protected override int ConvertToModelValue(string nbtValue)
		{
			int value;
			if (int.TryParse(nbtValue, NumberStyles.Integer, CultureInfo.InvariantCulture, out value))
				return value;
			return 0;
		}

		protected override Maybe<string> ConvertToNbtValue(int modelValue)
		{
			return modelValue.ToString(CultureInfo.InvariantCulture);
		}
	}
}